package com.sz.admin.dtutransportinfo.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.sz.admin.dtutransportinfo.pojo.dto.DtuTransportInfoCreateDTO;
import com.sz.admin.dtutransportinfo.pojo.dto.DtuTransportInfoListDTO;
import com.sz.admin.dtutransportinfo.pojo.dto.DtuTransportInfoUpdateDTO;
import com.sz.admin.dtutransportinfo.pojo.vo.DtuTransportInfoVO;
import com.sz.admin.dtutransportinfo.service.DtuTransportInfoService;
import com.sz.core.common.constant.GlobalConstant;
import com.sz.core.common.entity.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * DTU运输信息 Controller
 * </p>
 *
 * @author sz-admin
 * @since 2025-10-23
 */
@Tag(name = "DTU运输信息")
@RestController
@RequestMapping("dtu-transport-info")
@RequiredArgsConstructor
public class DtuTransportInfoController {

    private final DtuTransportInfoService dtuTransportInfoService;

    @Operation(summary = "新增")
    @SaCheckPermission(value = "dtu.transport.info.create", orRole = GlobalConstant.SUPER_ROLE)
    @PostMapping
    public ApiResult<Void> create(@RequestBody DtuTransportInfoCreateDTO dto) {
        dtuTransportInfoService.create(dto);
        return ApiResult.success();
    }

    @Operation(summary = "修改")
    @SaCheckPermission(value = "dtu.transport.info.update", orRole = GlobalConstant.SUPER_ROLE)
    @PutMapping
    public ApiResult<Void> update(@RequestBody DtuTransportInfoUpdateDTO dto) {
        dtuTransportInfoService.update(dto);
        return ApiResult.success();
    }

    @Operation(summary = "删除")
    @SaCheckPermission(value = "dtu.transport.info.remove", orRole = GlobalConstant.SUPER_ROLE)
    @DeleteMapping
    public ApiResult<Void> remove(@RequestBody SelectIdsDTO dto) {
        dtuTransportInfoService.remove(dto);
        return ApiResult.success();
    }

    @Operation(summary = "列表查询")
    @SaCheckPermission(value = "dtu.transport.info.query_table", orRole = GlobalConstant.SUPER_ROLE)
    @GetMapping
    public ApiResult<PageResult<DtuTransportInfoVO>> list(DtuTransportInfoListDTO dto) {
        return ApiPageResult.success(dtuTransportInfoService.page(dto));
    }

    @Operation(summary = "详情")
    @SaCheckPermission(value = "dtu.transport.info.query_table", orRole = GlobalConstant.SUPER_ROLE)
    @GetMapping("/{id}")
    public ApiResult<DtuTransportInfoVO> detail(@PathVariable Object id) {
        return ApiResult.success(dtuTransportInfoService.detail(id));
    }

    @Operation(summary = "导入")
    @Parameters({
      @Parameter(name = "file", description = "上传文件", schema = @Schema(type = "string", format = "binary"), required = true),
    })
    @SaCheckPermission(value = "dtu.transport.info.import")
    @PostMapping("/import")
    public void importExcel(@ModelAttribute ImportExcelDTO dto) {
        dtuTransportInfoService.importExcel(dto);
    }

    @Operation(summary = "导出")
    @SaCheckPermission(value = "dtu.transport.info.export")
    @PostMapping("/export")
    public void exportExcel(@RequestBody DtuTransportInfoListDTO dto, HttpServletResponse response) {
        dtuTransportInfoService.exportExcel(dto, response);
    }
}